<%@ page contentType="text/html; charset=GB2312"%>
<%@ page language="java" import="com.demo.util.Conn,java.sql.ResultSet,jxl.*,jxl.write.*,java.io.*
,java.text.SimpleDateFormat,java.util.Date"%>
<%
  	if(session.getAttribute("admin_user_id")==null)
  		response.sendRedirect("login.jsp");
	int nVal = 0;
	int nStudentNum = 0;
	int nFStudentNum = 0;
	int nRecruitersNum = 0;
	int nActiveRecruitersNum = 0;
	int nFRecruitersNum = 0;
	int nAdministratorsNum = 0;
	int nJobsNum = 0;
	int nAcitveJobsNum = 0;
	int nExpiredJobsNum = 0;
	int ndeletedJobsNum = 0;
	int nFJobsNum = 0;
	Conn objConn;
	ResultSet rs;
	
	StringBuffer sql = new StringBuffer();
	sql.delete(0, sql.length());
	objConn = new Conn();
	
	sql.append("select count(*) as num from DBF_StuUser");
	rs = objConn.find(sql.toString());
	if (rs != null && rs.next()){
		nStudentNum = rs.getInt("num");
		nFStudentNum = nStudentNum;
		rs.close();
	}
	
	
	sql.delete(0, sql.length());
	sql.append("select count(*) as num from DBF_INDUSTRY_INFO");
	rs = objConn.find(sql.toString());
	if (rs != null && rs.next()){
		nRecruitersNum = rs.getInt("num");
		nActiveRecruitersNum = nRecruitersNum;
		nFRecruitersNum = nActiveRecruitersNum;
		rs.close();
	}
	
	sql.delete(0, sql.length());
	sql.append("select count(*) as num from DBF_ADMIN_USER");
	rs = objConn.find(sql.toString());
	if (rs != null && rs.next()){
		nAdministratorsNum = rs.getInt("num");
		rs.close();
	}
	
	sql.delete(0, sql.length());
	sql.append("select count(*) as num from DBF_JOB_INFO");
	rs = objConn.find(sql.toString());
	if (rs != null && rs.next()){
		nJobsNum = rs.getInt("num");
		nFJobsNum = nJobsNum;
		nAcitveJobsNum = nJobsNum;
		rs.close();
	}
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
	String fileName="report_"+sdf.format(new Date())+".xls";
	String realPath=request.getRealPath("/");
	String filePath=realPath+"/excel/";
	try{
		WritableWorkbook book= Workbook.createWorkbook(new File(filePath+fileName)); 
		WritableSheet sheet=book.createSheet("First Page",0); 
		sheet.mergeCells(0,0,3,0); 
		sheet.setColumnView(0,40); 
		sheet.setColumnView(1,15); 
		sheet.setColumnView(2,40); 
		sheet.setColumnView(3,15); 
		Label label=new Label(0,0,"General reports"); 
		sheet.addCell(label);
		
		label=new Label(0,1,"Total no of students : "); 
		sheet.addCell(label);
		jxl.write.Number number = new jxl.write.Number(1,1,nStudentNum); 
		sheet.addCell(number);
		label=new Label(2,1,"Total no of jobs : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(3,1,nJobsNum); 
		sheet.addCell(number);
		
		label=new Label(0,2,"Total no of featured students : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(1,2,nFStudentNum); 
		sheet.addCell(number);
		label=new Label(2,2,"Total no of active jobs : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(3,2,nAcitveJobsNum); 
		sheet.addCell(number);
		
		label=new Label(0,3,"Total no of recruiters : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(1,3,nStudentNum); 
		sheet.addCell(number);
		label=new Label(2,3,"Total no of expired jobs : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(3,3,nExpiredJobsNum); 
		sheet.addCell(number);
		
		label=new Label(0,4,"Total no of active recruiters : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(1,4,nActiveRecruitersNum); 
		sheet.addCell(number);
		label=new Label(2,4,"Total no of deleted jobs :"); 
		sheet.addCell(label);
		number = new jxl.write.Number(3,4,ndeletedJobsNum); 
		sheet.addCell(number);
		
		label=new Label(0,5,"Total no of featured recruiters:  "); 
		sheet.addCell(label);
		number = new jxl.write.Number(1,5,nFRecruitersNum); 
		sheet.addCell(number);
		label=new Label(2,5,"Total no of featured jobs : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(3,5,nFJobsNum); 
		sheet.addCell(number);
		
		label=new Label(0,6,"Total no of administrator : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(1,6,nAdministratorsNum); 
		sheet.addCell(number);
		label=new Label(2,6,"Total no of other jobs : "); 
		sheet.addCell(label);
		number = new jxl.write.Number(3,6,nVal); 
		sheet.addCell(number);
		
		book.write(); 
		book.close(); 
	}catch(Exception e) {
		e.printStackTrace();
	} 
	
 
      
    response.reset();  
    response.setContentType("application/msexcel; charset=UTF-8");   
    response.setHeader("Content-Disposition", "attachment;filename=\""+fileName+"\"");   

	java.io.FileInputStream   fileInputStream   =   
      new java.io.FileInputStream(filePath+fileName);   

	ServletOutputStream servletOS = response.getOutputStream();
	    byte[] buf = new byte[4096];
	    int i;   
	    while (((i = fileInputStream.read(buf)) != -1)) {
	    	servletOS.write(buf, 0, i);
	}
	fileInputStream.close();   
    servletOS.flush();
    servletOS.close();
    
    out.clear();
    out = pageContext.pushBody(); 
	
	//response.sendRedirect("../excel/"+fileName);
%>

